{% extends '::admin.html.twig' %} 
{% block title %}
    Администраторская часть
{% endblock %}
{% block body %}
<h1>Staff edit</h1>

<form action="{{ path('admin_staff_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>
    <div class="form_fieldset">
      {{ form_label(edit_form.name) }}
      {{ form_widget(edit_form.name, {'attr': {'class': 'text' } }) }}
    </div>
    <div class="form_fieldset">
      {{ form_label(edit_form.file) }}
      {% if entity.path %}
        <img src="{{entity.getWebPath()}}"/>
      {% endif %}
      {{ form_widget(edit_form.file) }}
    </div>
    <div class="form_fieldset">
      {{ form_label(edit_form.description) }}
      {{ form_widget(edit_form.description, {'attr': {'class': 'tinymce', 'tinymce': '{"theme":"simple"}' } }) }}
    </div>
    <div class="form_fieldset">
      {{ form_label(edit_form.category) }}
      {{ form_widget(edit_form.category, {'attr': {'class': 'text' } }) }}
    <a href="{{ path('admin_staff_category') }}">Редактировать категорию</a>
    </div>
    <div class="form_fieldset">
      {{ form_label(edit_form.firm) }}
      {{ form_widget(edit_form.firm, {'attr': {'class': 'text' } }) }}
      <a href="{{ path('admin_firms_edit',{'id': entity.firm.id}) }}">Редактировать Фирму</a>
    </div>
      {{ form_rest(edit_form) }}
    <p>
        <button type="submit">Edit</button>
    </p>
</form>
<div>
  <div class="comment_2 ui-corner-all">
    <div class="comment_2_header">
      <div class="comment_2_content">Отзывы:</div>
      <div class="comment_2_button">
        <input type="button" id="add_comment_button" value="Добавить Отзыв" />
      </div>
    </div>
    {% for comment in entity.getComments() %}
      {% include 'AcmeStaffBundle:Comment:index.html.twig' with {'comment': comment, 'padding': 0} %}
      </br>
    {% endfor %}
  </div>
  <div id="add_comment" title="Добавить Отзыв">
  <form action="{{ path('admin_save_staff_comment', {'staff_id': entity.getId() }) }}" method="POST" id="form_add_comment"  >
                            {{ form_widget(add_comment_form) }}
    
  </form>  
  </div>
</div>
<ul class="record_actions">
    <li>
        <a href="{{ path('admin_staff') }}">
            Back to the list
        </a>
    </li>
    <li>
        <form action="{{ path('admin_staff_delete', { 'id': entity.id }) }}" method="post">
            {{ form_widget(delete_form) }}
            <button type="submit">Delete</button>
        </form>
    </li>
</ul>
{% endblock %}
{% block post_javascripts %}
  {{ parent() }}
  {{ tinymce_init() }}
  <script type="text/javascript">
  $(document).ready(function(){
    $('button, input:button').button();
    
      $( "div#add_comment" ).dialog({ autoOpen: false,
                                      height: 400,
                                      width: 550,
                                      modal: true,
                                      buttons: { "Add Comment": function() {
                                                                  $( this ).dialog( "close" );
                                                                  $('#form_add_comment').submit();
                                                                },
                                                 Cancel: function() {
                                                          $( this ).dialog( "close" );
                                                         }
                                                }});
    $("#add_comment_button").click(function(){
      $('#form_add_comment').attr('action', "{{ path('admin_save_staff_comment', {'staff_id': entity.getId() }) }}");
      $( "div#add_comment" ).dialog("open");
    });
    $(".add_c").click(function() {
      $('#form_add_comment').attr('action', "{{ path('admin_save_staff_comment', {'staff_id': entity.getId() }) }}" + "/" + $(this).attr('id'));
      $( "div#add_comment" ).dialog("open");
      return false;
    });
    $(".ui-icon-closethick").click(function() {
      var url = $(this).attr('href'),
          parent = '#parent_comment'+$(this).attr('id');
      $.post(url, function() {
        $(parent).slideUp();
      });
      return false;
    });
    $(".ui-icon-pencil").click(function(){
      var url = $(this).attr('href'),
          text = $('#comment_text'+$(this).attr('id')).html();
      $('#form_add_comment').attr('action', url);
      $("div#add_comment").find('textarea').html(text);
      $( "div#add_comment" ).dialog("open");
      return false;
    });
  });
  </script>
{% endblock %}